﻿<%@ Page Title="留言管理" Language="C#" MasterPageFile="Function.Master" AutoEventWireup="true" CodeBehind="messageslist.aspx.cs" Inherits="LEARNREN.COM.WebSite.Admin.messageslist" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        var edit_pannel;
        var dataTableInPage;

        $(document).ready(function () {
            dataTableInPage = showDataTable();
            init_edit_pannel();

        });
        function showDataTable() {
            var dt = dataTableExt("messageslist.ashx", "dataTable",
                        [{ "sClass": "center", "mDataProp": "MsgTitle" },
                        { "sClass": "center", "mDataProp": "MsgPhone" },
                        { "sClass": "center", "mDataProp": "MsgQQ" },
                        { "sClass": "center", "mDataProp": "MsgMail" },
                        { "sClass": "center", "mDataProp": "CreatedTime", "width": 130 },
                        { "sClass": "center", "mDataProp": "MsgHasRe", "width": 40 },
                        {
                            //自定义列
                            "mDataProp": "Id",
                            "width": 120,
                            "sClass": "center",
                            "bSearchable": false,
                            "bStorable": false,
                            "bStateSave": true,
                            "mRender": function (obj, display, fullData) {
                                return '<a href="#" class="inlineButton" onclick=\"showEditpannel(' + obj + ');return false;\">回复</a>&nbsp;&nbsp;<a href=\"#\" class="inlineButton" onclick=\"deleteMessage(' + obj + ');return false;\">删除</a>';
                            }
                        }]);
            return dt;
        }

        function showEditpannel(id) {
            $.post("MessageHandler.ashx",
                   { o: 2, id: id },
                    function (data) {
                        $("#hid_id").val(id);
                        $("#txt_title").val(data.MsgTitle);
                        $("#txt_content").val(data.MsgContent);
                        $("#txt_reply").val(data.MsgRe);
                    },
                     "json");
            edit_pannel.dialog("open");
            return false;
        }

        function saveReply() {
            var id = $("#hid_id").val();
            var reply = $("#txt_reply").val();
            $.post("MessageHandler.ashx",
            { o: 1, id: id, r: reply },
            function (data) {
                if (data.result) {
                    edit_pannel.dialog("close");
                    dataTableInPage.fnStandingRedraw();
                }
                else {
                    alert("回复失败。");
                }
            },
            "json");
        }

        function deleteMessage(id) {
            if (confirm("确定要删除此留言吗？")) {
                $.post("MessageHandler.ashx",
                { o: 0, id: id },
                function (data) {
                    if (!data) {
                        showDialog("删除失败！", "提示");
                    }
                    else {
                        if (data.result) {
                            showDialog("删除成功！", "提示");
                            if (dataTableInPage) {
                                dataTableInPage.fnStandingRedraw();
                            }
                        }
                        else {
                            showDialog("删除失败！", "提示");
                        }
                    }
                },
                "json");
            }
            return false;
        }

        function init_edit_pannel() {
            edit_pannel = $("#edit_pannel").dialog({
                autoOpen: false,
                title: "留言回复",
                modal: true,
                buttons: {
                    "确定": function () { saveReply(); },
                    "取消": function () { $(this).dialog("close"); }
                },
                width: 430
            });
            edit_pannel.find("form").submit(function (event) {
                event.preventDefault();
                saveReply();
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="dataTable" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>标题</th>
                <th>电话</th>
                <th>QQ</th>
                <th>邮箱</th>
                <th>发布时间</th>
                <th>已回</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
    <div id="edit_pannel" title="回复留言">
        <form action="MessageHandler.ashx?o=1" method="post">
        <p>
            <label for="txt_title" class="block">标题</label>
            <input id="txt_title" name="txt_title" type="text" tabindex="-1" class="block" readonly="readonly" /></p>
        <p>
            <label for="txt_content" class="block">内容</label>
            <textarea rows="5" id="txt_content" name="txt_content" tabindex="-1" class="block" readonly="readonly"></textarea></p>
        <p>
            <label for="txt_reply" class="block">回复</label>
            <textarea rows="5" id="txt_reply" name="txt_reply" class="block"></textarea></p>
        <input type="hidden" id="hid_id" name="hid_id" />
        <input type="submit" tabindex="-1" style="position: absolute; top: -1000px" />
        </form>
    </div>
</asp:Content>
